

function sexa(sex)
{
	if(sex == "男")
	{
		return "../images/boy.jpg";
	}
	else
	{
		return "../images/gird.jpg";
	}
	
}
function allUser()
{
    $.ajax({
    	type:'get',
    	url:'/chat/OnlineServlet?method=allUser',
    	dataType:'json',
    	success:function(data)
    	{
    		 $('.weui-cells').empty();
    		for(var i=0;i<data.length;i++)
    		{
    			var id = data[i].id;
    			var name = data[i].username;
    			var note = data[i].note;
    			var sex = data[i].sex;
    			
    			var html = "<a href='/chat/view/online/desc.jsp?id="+id+"'>"
					+ "<div class='weui-cell'>"
				      +"<div class='weui-cell__hd' style='position: relative;margin-right: 10px;'>"
				           +"<img src="+sexa(sex)+" style='width: 50px;display: block'>"
				        +" </div>"
				        +" <div class='weui-cell__bd'>"
				         +"<p >"+name+"</p>"
				             +"<p  style='font-size: 13px;color: #888888;'>"+note+"</p>"
				       +" </div>"
				    +" </div>"
				 +" </a>";
				 $('.weui-cells').append(html);
				 
    		}
    		
    		$('#title').text("全部用户");
    	},
    	error:function(msg)
    	{
    		
    	}
    });
}

function online()
{
    $.ajax({
    	type:'get',
    	url:'/chat/OnlineServlet?method=online',
    	dataType:'json',
    	success:function(data)
    	{
    		 $('.weui-cells').empty();
    		for(var i=0;i<data.length;i++)
    		{
    			var id = data[i].id;
    			var name = data[i].username;
    			var note = data[i].note;
    			var sex = data[i].sex;
    			var html = "<a href='/chat/view/online/desc.jsp?id="+id+"'>"
					+ "<div class='weui-cell'>"
				      +"<div class='weui-cell__hd' style='position: relative;margin-right: 10px;'>"
				           +"<img src="+sexa(sex)+" style='width: 50px;display: block'>"
				        +" </div>"
				        +" <div class='weui-cell__bd'>"
				         +"<p >"+name+"</p>"
				             +"<p  style='font-size: 13px;color: #888888;'>"+note+"</p>"
				       +" </div>"
				    +" </div>"
				 +" </a>";
    			
				 $('.weui-cells').append(html);
				 
    		}
    		$('#title').text("在线用户");
    	},
    	error:function(msg)
    	{
    		
    	}
    });
}
//function lastupdatetime()
//{
//	$.ajax({
//    	type:'get',
//    	url:'/chat/OnlineServlet?method=lastupdatetime',
//    	dataType:'json',
//    	success:function(data)
//    	{
//    		
//    	},
//    	error:function(msg)
//    	{
//    		
//    	}
//    });
//}
function desc()
{
	var id = $('#id').val();
	$.ajax({
  	type:'get',
  	url:'/chat/DescServlet?id='+id,
  	dataType:'json',
  	success:function(data)
  	{
  		var status = null;
  		var mode = null;
  		for(var i=0;i<data.length;i++)
		{
  			$('#title').text(data[i].username);
			$('#name').text(data[i].username);
			$('#sex').text(data[i].sex);
			$('#birthday').text(data[i].birthday);
			$('#email').text(data[i].email);
			$('#phone').text(data[i].phone);
			$('#note').text(data[i].note);
			
			if(data[i].status ==0)
			{
				status = "BOSS";
			}
			if(data[i].status ==1)
			{
				status = "管理员";
			}
			if(data[i].status ==2)
			{
				status = "普通用户";
			}
			$('#status').text(status);
			if(data[i].mode ==0)
			{
				mode = "禁言";
			}
			if(data[i].mode ==1)
			{
				mode = "可用";
			}
			$('#mode').text(mode);
		}
  		
  	},
  	error:function(msg)
  	{
  		
  	}
  });
}

function info()
{
	var info = $('#text').val();
	
	$.ajax({
  	type:'post',
  	url:'/chat/InfoServlet',
  	dataType:'json',
  	data:
  	{  
  		content:info
  	}, 
  	success:function(data)
  	{
  		
		  
	  
  	},
  	error:function(msg)
  	{
  		
  	}
  });
}

function divv(sessionid,id)
{
	if(sessionid==id)
	{
		return "style='margin-left:80%'";
	}
	else
	{
		return "";
	}
}

function selectinfo()
{
	var sessionid = document.getElementById('sessionid').value;
	var mai = document.getElementById('area');
	$.ajax(
	{
  	type:'get',
  	url:'/chat/InfoServlet',
  	dataType:'json',
  	
  	success:function(data)
  	{
  		
  		 $('#area').empty();
  		for(var i=0;i<data.length;i++)
		{
  			var name = data[i].user.username;
  			var sendtime = data[i].sendtime;
  			var content = data[i].content;
  			var id = data[i].user.id;
  			var html ="<div  class='demo clearfix' "+divv(sessionid,id)+"  >"
							+ "<div class='article'>"
								+ "<div>"
								+ "<div class='name'>"+name+"&nbsp&nbsp"+sendtime+"</div><br/>"
								+ "</div>"
								+ "<div>"+content+"</div>"
							+ "</div>"
						+ "</div>";
  			$('#area').append(html);
  			mai.scrollTop=mai.scrollHeight; 
		}
  		
  	},
  	error:function(msg)
  	{
  		
  	}
  });
}
function onliner()
{
	
	$.ajax(
	{
  	type:'get',
  	url:'/chat/OnlineServlet?method=onliner',
  	dataType:'json',
  	
  	success:function(data)
  	{
  		$('#num').text("在线人数:"+data+"人");
  	},
  	error:function(msg)
  	{
  		
  	}
  });
}


